#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/*
 * Copyright © 2014, Finium Sdn Bhd, All Rights Reserved
 * 
 * JsonDateSerializer.java
 * Modification History
 * *************************************************************
 * Date				Author						Comment
 * Feb 22, 2012		Venkaiah Chowdary Koneru	Created
 * *************************************************************
 */
package ${package}.support;

import java.io.IOException;
import java.util.Date;

import ${package}.AppConstants;

import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.JsonSerializer;
import org.codehaus.jackson.map.SerializerProvider;
import org.springframework.stereotype.Component;

/**
 * Used to serialize Java.util.Date, which is not a common JSON type, so we have
 * to create a custom serialize method.
 * 
 * @author Venkaiah Chowdary Koneru
 * @see JsonSerializer
 */
@Component
public class JsonDateSerializer extends JsonSerializer<Date>
{
    private final ThreadSafeDateFormat dateFormat = new ThreadSafeDateFormat(
            AppConstants.MARSHALLER_OR_SERIALIZER_DATE_FORMAT);

    /**
     * converts the date object to string format
     * 
     * @param date
     * @param gen
     * @param provider
     * 
     * @throws IOException
     *             in case of errors
     */
    @Override
    public void serialize(Date date, JsonGenerator gen,
            SerializerProvider provider) throws IOException
    {
        String formattedDate = dateFormat.format(date);

        gen.writeString(formattedDate);
    }
}
